<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var CreateDiv = function (html) {
        this.html = html
        this.init()
      }

      CreateDiv.prototype.init = function () {
        var div = document.createElement('div')
        div.innerHTML = this.html
        document.body.append(div)
      }

      // 接下来引入代理类
      var proxySingletonCreateDiv = (function () {
        var instance
        return function (html) {
          if (!instance) {
            instance = new CreateDiv(html)
          }
          return instance
        }
      })()

      var a = new proxySingletonCreateDiv('wangxin1')
      var b = new proxySingletonCreateDiv('wangxin2')

      console.log(a === b) // true
    </script>
  </body>
</html>
